﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using TypeMock.ArrangeActAssert;
using TypeMock.DataLayer;

namespace TypeMockDemo.DataLayer.Fixtures
{
    [TestFixture]
    [Category("DataLayer")]
    public sealed class UnitOfWorkFixture
    {
        [Test]
        [Category("DataLayer")]
        public void CanMarkANewEntityToNewAndChangeItsId()
        {
            Person person = Isolate.Fake.Instance<Person>();
            IUnitOfWork uow = Isolate.Fake.Instance<IUnitOfWork>();
            Isolate.WhenCalled(() => 
                uow.MarkNew(person))
                .DoInstead(callContext =>
                               {
                                   var p = callContext.Parameters[0] as Person;
                                   p.UniqueId = Guid.NewGuid();
                                   p.IsNew = true;
                                   return p;
                               });
            person.UniqueId = Guid.NewGuid();
            person.IsNew = true;
            Isolate.WhenCalled(() => uow.MarkNew<Person>(person)).WillReturn(person);
            var expectedPerson = uow.MarkNew(person);
            Assert.That(expectedPerson.UniqueId, Is.Not.EqualTo(Guid.Empty));
            Assert.That(expectedPerson.IsNew, Is.True);
        }

        [Test]
        [Category("DataLayer")]
        public void CanMarkAnUpdatedEntityToDirty()
        {

        }
        [Test]
        [Category("DataLayer")]
        public void CanMarkADeletedEntityToDeleted()
        {

        }

    }
}
